<?php

/**
 * Created by tinymeng Model.
 */
namespace App\Models\CacheDb;

use Illuminate\Support\Facades\Cache;

/**
 * Class CommonModel
 * @method static \Illuminate\Cache\TaggedCache tags(array|mixed $names)
 * @method static \Illuminate\Contracts\Cache\Lock lock(string $name, int $seconds = 0, mixed $owner = null)
 * @method static \Illuminate\Contracts\Cache\Lock restoreLock(string $name, string $owner)
 * @method static \Illuminate\Contracts\Cache\Repository  store(string|null $name = null)
 * @method static \Illuminate\Contracts\Cache\Store getStore()
 * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null)
 * @method static bool flush()
 * @method static bool forever(string $key, $value)
 * @method static bool forget(string $key)
 * @method static bool has(string $key)
 * @method static bool missing(string $key)
 * @method static bool put(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null)
 * @method static int|bool decrement(string $key, $value = 1)
 * @method static int|bool increment(string $key, $value = 1)
 * @method static mixed get(string $key, mixed $default = null)
 * @method static mixed pull(string $key, mixed $default = null)
 * @method static mixed remember(string $key, \DateTimeInterface|\DateInterval|int $ttl, \Closure $callback)
 * @method static mixed rememberForever(string $key, \Closure $callback)
 * @method static mixed sear(string $key, \Closure $callback)
 *
 * @see \Illuminate\Cache\CacheManager
 * @see \Illuminate\Cache\Repository
 */
class CommonModel extends Cache
{
    /**
     * @var string
     */
    protected $table;
    /**
     * @var null
     */
    protected $second = null;

    /**
     * 获取表名
     * @return string
     */
    public function getTable(): string
    {
        return $this->table;
    }

    /**
     * 设置缓存
     * @param $value
     * @return bool
     */
    public function setValue($value): bool
    {
        return self::put($this->getTable(),$value,$this->second);
    }

    /**
     * 获取缓存
     * @return mixed
     */
    public function getValue(){
        return self::get($this->getTable());
    }

    /**
     * 删除缓存
     * @return bool
     */
    public function delete(): bool
    {
        return self::forget($this->getTable());
    }
}
